
$.extend({
	mask : function(obj){
        var op = $.extend({
			top: 0,
			left: 0,
			background: "#000",
            opacity: .5,
            zIndex: 999
        },obj);
        if (!$.maskDiv) {
            $.maskDiv = $('<div id="jq_mask"></div>');
            $.maskDiv.appendTo(document.body);			
        };
		$(window).bind("scroll resize", 
			function() {
				$.maskDiv.css({
					width: $(window).width(),
					height: $(document).height()
				})
			}
		); 		
		$("#jq_mask").show();
        $.maskDiv.css({
            position: "absolute",
            top: op.top,
            left: op.left,			
			backgroundColor: op.background,
            width: $(window).width(),
            height: $(document).height(),
            opacity: op.opacity,
			zIndex: op.zIndex
        });		
        return $.maskDiv;		
	},
    unmask: function(c) {
		$("#jq_mask").hide();
		$(window).unbind("scroll resize")
    }	
});
$.extend($.fn, {
//弹窗局中
	center : function(){
        var that = $(this);
        var oWidth = that.width() / 2;
        var oHeight = that.height() / 2;
		var winh = $(window).height()/2;
        var css = {
              position : "fixed",
                  left : "50%",
                   top : "50%",
            marginLeft : -oWidth,
             marginTop : -oHeight,
			 zIndex: 1000
        };
        if (!window.XMLHttpRequest) {
			css.position = "absolute";  
			var scolIE6Fun = function(){
				var st = $(document).scrollTop(); 				
                that.css({
                    top : $(window).height()/2 + st
                })								
			};
			$(window).bind("scroll resize", scolIE6Fun);
        }
        that.css(css);
        that.show();
        return that;		
	},
	//弹窗alert
	winOpen : function(callback){
		var that = this;
		that.center();
		$.mask();
		var closeEvent = function(){
			that.hide();
			if(!$(".gol_win_tips").is(":visible")){$.unmask();};
			
			callback && callback();			
		};
		$(that).find(".a_close").unbind("click").click(function(){
			closeEvent();
		});
		$('.qx').unbind("click").click(function(){
			closeEvent();
		});
		$("body").unbind("keydown").bind("keydown",function(e){
			if(e.keyCode == 27){ 
				closeEvent();
			}		
		});	
	},
	play : function(opts){
		var that = $(this);
		var def = {
		   		movePx : 1190,
			   picList : ".pic_list",
			   navList : ".nav_list",
			   	   pre : ".prev",
				  next : ".next",	  
			       cur : "cur",
			     times : 4000
		};
		var setting = $.extend(def,opts);
		var index = 0,
		timer,			
		liArrLen = that.find(setting.picList).children().length;
		
	/*	that.find(setting.picList).css({
			"position" : "absolute",
			   "width" : 9999
		});*/

		var	navList = function(){
			var b = '<ul class="'+setting.navList.substring(1)+'">';
			for (var i = 1; i <= liArrLen; i++) {
				b += '<span></span>';
			};
			b += '</ul>';
			that.append(b);
		}();
		that.append('<span class="prenexticon prenextbg_'+setting.pre.substring(1)+' '+setting.pre.substring(1)+'"></span><span class="prenexticon prenextbg_'+setting.next.substring(1)+' '+setting.next.substring(1)+'"></span>');
		that.append('<span class="prenexticon prenextbtn_'+setting.pre.substring(1)+' '+setting.pre.substring(1)+'"></span><span class="prenexticon prenextbtn_'+setting.next.substring(1)+' '+setting.next.substring(1)+'"></span>');
		that.find(setting.navList).children().mouseenter(function(){
			index = that.find(setting.navList).children().index(this);
			showPics(index);
		}).eq(0).trigger("mouseenter");	
		that.hover(clearTime,Time).trigger("mouseleave");
		
        that.find(setting.next).click(function(){
			index += 1;
			if(index== liArrLen) {index = 0;}
			showPics(index);
		});
			
		that.find(setting.pre).click(function(){
			index -= 1;
			if(index == -1) { index = liArrLen-1;}
			showPics(index);			
		});					
		function showPics(index) { 	
/*			var leftPx = setting.movePx * -index;
			that.find(setting.picList).stop(true,false).animate({left : leftPx},500);*/
			that.find(setting.picList).children().stop(true,false).eq(index).css("z-index","1").animate({opacity:1},1000).siblings().css("z-index","0").animate({opacity:0},1000)
			that.find(setting.navList).children().eq(index).addClass(setting.cur).siblings().removeClass(setting.cur);
		};			
		function Time(){
			clearInterval(timer);
			$(".prenexticon").hide();
			$(".prenexticon").hide();
			timer = setInterval(function(){				 
				index++;
				if(index > liArrLen - 1){
					showPics(index);	
					index = 0;
				}
				showPics(index);			
			},setting.times)				
		};
		function clearTime(){
			$(".prenexticon").show();
			$(".prenexticon").show();
			clearInterval(timer);
		};					
	},
	tab : function(opts){
		var def = {
			tabBd : "",
			  cls :"cur",
		   _event :"mouseover"
		};
		var setting = $.extend(def,opts);	
		$(this).bind(setting._event ,fn).eq(0).trigger(setting._event);
		
		function fn(){
			var index = $(this).index();
			$(this).addClass(setting.cls).siblings().removeClass(setting.cls);
			$(setting.tabBd).eq(index).show().siblings().hide();
			if(opts.fun)opts.fun(index);		
		};
	},
	tabcur : function(opts){
		var def = {
			  cls :"cur",
		   _event :"click"
		};
		var setting = $.extend(def,opts);	
		$(this).bind(setting._event ,fn).eq(0).trigger(setting._event);
		
		function fn(){
			$(this).addClass(setting.cls).siblings().removeClass(setting.cls);
		};
	}
});

function FnCheck(element,value){
	if(value == 1){
		reg=/^[\u4e00-\u9fa5]{2,4}$/;   //验证汉字
		if(!reg.test($(element).val())){
			fnShow(element)
		}else{
			fnHide(element)
		}
	}
	if(value == 2){
		reg=/^1[3|4|5|8][0-9]\d{8}$/i;  //验证手机
		if(!reg.test($(element).val())){
			fnShow(element)
		}else{
			fnHide(element)
		}
	}
	if(value == 3){
		reg=/^\+?[1-9][0-9]*$/i;//验证数字
		if(!reg.test($(element).val())){
			fnShow(element)
		}else{
			fnHide(element)
		}
	}
	if(value == 0){
		if($(element).val() == ''){
			fnShow(element)
		}else{
			fnHide(element)
		}
	}
	if(value == 5){
		reg=/^[1-9]\d{5}(19\d{2}|[2-9]\d{3})((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])(\d{4}|\d{3}X)$/i; //验证身份证位数
		if(!reg.test($(element).val())){
			fnShow(element)
		}else{
			fnHide(element)
		}
	}
		
	function fnShow(e){
		$(e).addClass("errorC");
		$(e).parents('.form-item').find('.item-notice').show();

		if($(e).parents('.item_parent').find('.errorC').length == 0 ){
			$('#form-bd').attr('data-form','1')
		}else{
			$('#form-bd').attr('data-form','0')
		}
	}
	function fnHide(e){
		$(e).removeClass("errorC");
		$(e).parents('.form-item').find('.item-notice').hide();				
		if($(e).parents('.item_parent').find('.errorC').length == 0 ){
			$('#form-bd').attr('data-form','1')
		}else{
			$('#form-bd').attr('data-form','0')
		}
	}


}